﻿using Microsoft.EntityFrameworkCore;
using NewRetail.Application.Components.StoreValueCard.Entity;
using NewRetail.Application.Components.WeChat.CardVoucher.Entity;
using NewRetail.Application.Core.Entity;

namespace NewRetail.Application.Components.WeChat.CardVoucher
{
    public static class CardVoucherExtension
    {
        public static void ConfigureCardVoucherEntities(this ModelBuilder modelBuilder)
        {           
            //代金券表
            var infoBuilder = modelBuilder.Entity<CardVoucherInfo>().ConfigBaseEntity();
            infoBuilder.ToTable("pos_card_voucher");
            infoBuilder.Property(x => x.stockId).IsRequired().HasMaxLength(30);
            infoBuilder.Property(x => x.outRequestNo).IsRequired().HasMaxLength(150);
            infoBuilder.Property(x => x.availableBeginTime).IsRequired().HasMaxLength(40);
            infoBuilder.Property(x => x.availableEndTime).IsRequired().HasMaxLength(40);
            infoBuilder.Property(x => x.stockName).HasMaxLength(30);
            infoBuilder.Property(x => x.stockType).HasMaxLength(20);

        }

        public static void ConfigureUserCouponsEntities(this ModelBuilder modelBuilder)
        {
            //用户领券表
            var infoBuilder = modelBuilder.Entity<UserCouponsInfo>().ConfigBaseEntity();
            infoBuilder.ToTable("pos_user_coupons");
            infoBuilder.Property(x => x.outRequestNo).IsRequired().HasMaxLength(150);
            infoBuilder.Property(x => x.openId).IsRequired().HasMaxLength(150);
            infoBuilder.Property(x => x.stockId).IsRequired().HasMaxLength(20);
            infoBuilder.Property(x => x.couponId).IsRequired().HasMaxLength(20);

        }
        public static void ConfigureCardVoucherIntegralEntities(this ModelBuilder modelBuilder)
        {
            //积分兑换券设置表
            var infoBuilder = modelBuilder.Entity<CardVoucherIntegralInfo>().ConfigBaseEntity();
            infoBuilder.ToTable("pos_cardvoucher_integral");
            infoBuilder.Property(x => x.stockId).IsRequired().HasMaxLength(20);
            infoBuilder.Property(x => x.cardVoucherId).IsRequired().HasMaxLength(50);
            infoBuilder.Ignore(x => x.CardVoucherInfo);
        }
        public static void ConfigureCardRechargeRecordEntities(this ModelBuilder modelBuilder)
        {
            //充值记录表
            var infoBuilder = modelBuilder.Entity<CardRechargeRecordEntity>().ConfigBaseEntity();
            infoBuilder.ToTable("cardrecharge_record");
            //infoBuilder.Property(x => x.openId).IsRequired().HasMaxLength(50);
            infoBuilder.Property(x => x.outTradeNumber).IsRequired().HasMaxLength(35);
        }
        public static void ConfigureCardRechargeSchemeEntities(this ModelBuilder modelBuilder)
        {
            //充值方案表
            var infoBuilder = modelBuilder.Entity<CardRechargeSchemeEntity>().ConfigBaseEntity();
            infoBuilder.ToTable("cardrecharge_scheme");
            infoBuilder.Property(x => x.rechargeAmount).IsRequired();
        }
        public static void ConfigureCardBalanceChangesEntities(this ModelBuilder modelBuilder)
        {
            //储值卡余额变化记录表
            var infoBuilder = modelBuilder.Entity<CardBalanceChangeEntity>().ConfigBaseEntity();
            infoBuilder.ToTable("cardbalance_change");
            infoBuilder.Property(x => x.changeAmount).IsRequired();
        }
    }
}
